<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'shedule.jsp' starting page</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/fullcalendar.css"></link>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/fullcalendar.print.css" media='print' ></link>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.10.2.custom.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
	
	<script type="text/javascript">
			$(function(){
				var date = new Date();
				var d = date.getDate();
				var m = date.getMonth();
				var y = date.getFullYear();
				
				$('#calendar').fullCalendar({
					editable: true,
					dayClick: function(date, allDay, jsEvent, view) {
						$("#table").css("display","block");
						changeInfo();
						$("#save").css("display","none");
						$("#update").css("display","inline");
						$("#delete").css("display","inline");
						 $('#win').window({   
						    width:600,   
						    height:400,   
						    modal:true,
						    title:'新增日程',
						});  
						$('#starttime').datetimebox({   
						    value: '3/4/2017 00:00',   
						    required: true,   
						    showSeconds: true  
						});
						$('#endtime').datetimebox({   
						    value: '3/4/2017 23:59',   
						    required: true,   
						    showSeconds: true   
						});
						$('#cont').combotree({   
						    url: '${pageContext.request.contextPath}/shedule?op=showcombooTree',   
						    multiple: true,
						    onBeforeExpand:function(node,param){
						    	$('#cont').combotree("tree").tree("options").url='${pageContext.request.contextPath}/shedule?op=showcombooTree';
							},
					        cascadeCheck:false,
					        onlyLeafCheck:true
						});
						$("form").attr("action","${pageContext.request.contextPath}/shedule?op=doadd");
						$("#save").css("display","inline");
						$("#update").css("display","none");
						$("#delete").css("display","none");
						
						$("input[name='tital']").val("");
						$("#uname").text("");
						$("textarea[name='content']").val("");
						$("input[name='address']").val("");

					},
					eventClick: function(event, jsEvent, view) {
						 $.getJSON("shedule.html?op=showone&id="+event.id,function(result){
								 //点击后 获取 josn对象成功后 打开调用打开win窗口函数并向其中插入数据
								 $("#table").css("display","block");
								 $('#win').window({   
								    width:600,   
								    height:400,   
								    modal:true,
								    title:'新增日程',
								});  
								$('#starttime').datetimebox({   
								    value: '3/4/2017 00:00',   
								    required: true,   
								    showSeconds: true  
								});
								$('#endtime').datetimebox({   
								    value: '3/4/2017 23:59',   
								    required: true,   
								    showSeconds: true   
								});
								$('#cont').combotree({   
								    url: '${pageContext.request.contextPath}/shedule?op=showcombooTree',   
								    multiple: true,
								    onBeforeExpand:function(node,param){
								    	$('#cont').combotree("tree").tree("options").url='${pageContext.request.contextPath}/shedule?op=showcombooTree';
									},
							        cascadeCheck:false,
							        onlyLeafCheck:true
									
								});
								$("input[name='tital']").val(result.tital);
								$("#uname").text(result.user.realname);
								$("#starttime").datetimebox('setValue', result.starttime);
								$("#endtime").datetimebox('setValue',result.endtime);
	  							$("input[name='persontype'][value="+result.persontype+"]").attr("checked","checked");
								$("input[name='address']").val(result.address);
								$("input[name='shareshedule'][value="+result.shareshedule+"]").attr("checked","checked");
								$("input[name='depttype'][value="+result.depttype+"]").attr("checked","checked");
								$("textarea[name='content']").val(result.content);
								var uid = $("#sys_user").val();

								var arr = new Array();
								for(var i=0;i<result.conts.length;i++){
									arr[i]=result.conts[i].user.realname;
								}								
								$("#cont").combotree('setValues',arr);
								if(uid==result.user.id){
									changeInfo();
									$("#save").css("display","none");
									$("#update").css("display","inline");
									$("#delete").css("display","inline");
									$("#id").val(event.id);
								}else{
									readInfo();
									$("#save").css("display","none");
									$("#update").css("display","none");
									$("#delete").css("display","none");
								}
						});
					},
					eventSources: [
						'${pageContext.request.contextPath}/shedule?op=showcale',
						'${pageContext.request.contextPath}/shedule?op=showdeptcale'
					]
					
				});
			});
			function readInfo(){
				$(".change").attr("readonly","readonly");
				$(".changer").attr("disabled","disabled");
			}
			function changeInfo(){
				$(".change").removeAttr("readonly");
				$(".changer").removeAttr("disabled");
			}	
			function doupdate(){
				$("form").attr("action","${pageContext.request.contextPath}/shedule?op=doupdate");
				$("form").submit();
			}
			function dodelete(){
				var id = $("#id").val();
				alert(id);
				$("form").attr("action","${pageContext.request.contextPath}/shedule?op=dodelete");
				$("form").submit();
			}
			$(function(){
				$("form").submit(function(){
					var tital = $("input[name='tital']").val();
					var starttime = $("#starttime").datetimebox('getValue');
					var endtime = $("#endtime").datetimebox('getValue');
					if(tital==""){
						alert("主题不能为不空");
						return false;
					}
					return true;
				});
			});
	</script>
<style>

	body {
		margin-top: 40px;
		text-align: center;
		font-size: 14px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
	}

	#calendar {
		width: 900px;
		margin: 0 auto;
	}
	#table{
		margin: 10px;
	} 
	#table td{
		padding: 6px
	}

</style>
</head>
   <body>
  	<div id='calendar'></div>
  	<div id="win">
  		<form action="" method="post">
  			<input type="hidden" value="${sys_user.id }" id="sys_user">
  			<input type="hidden" value="" name="id" id="id">
		  		<table id = "table" style="display: none;">
		  			<tr>
		  				<td>主题：</td>
		  				<td>
		  					<input class="change" type="text" value="" name="tital"/>发布人：<span id="uname"></span>
		  				</td>
		  			</tr>
		  			<tr>
		  				<td>时间段：</td>
		  				<td>
		  					<input class="changer" id="starttime" type="text" name="starttime"/> -
		  					<input class="changer" id="endtime" type="text" name="endtime"/>
		  				</td>
		  			</tr>
		  			<tr>
		  				<td>事务类型：</td>
		  				<td>
		  					<input  class="changer" type="radio" name="persontype" value="1" checked="checked">工作事务 <input  class="changer" type="radio" name="persontype" value="0">个人事务
		  				</td>
		  			<tr>
		  				<td>地点：</td>
		  				<td>
		  					<input class="change" id="address" type="text" name="address"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		  					[是否公开：<input  class="changer" type="radio" name="shareshedule" value="1" checked="checked">是 
		  							<input  class="changer" type="radio" name="shareshedule" value="0">否]	
						</td>	
		  			</tr>
		  			<tr>
		  				<td>预约他人：</td>
		  				<td>
		  					<input class="change" id="cont" name="cont" value="" size="30">
			  				<c:if test="${sys_user.role.id==3}">	
			  					[部门日程：<input  class="changer" type="radio" name="depttype" value="1" checked="checked">是 
			  							<input  class="changer" type="radio" name="depttype" value="0">否]
			  				</c:if>
		  				</td>
		  			</tr>
		  			<tr>
		  				<td colspan="1">内容：</td>
		  				<td colspan="1"><textarea  class="change" id="tarea" name="content" cols="40" rows="7"></textarea></td>
		  			</tr>
		  			<tr>
		  				<td colspan="1"></td>
		  				
		  				<td colspan="1">
		  				<span id="save">
		  					<input type="submit" value="保存">
		  				</span>
		  				<span id="update">
		  					<input type="button" value="修改" onclick="doupdate()">
		  				</span>
		  				<span id="delete">
		  					<input type="button" value="删除" onclick="dodelete()">
		  				</span>
		  				</td>
		  			</tr>
		  		</table>
	  	</form>
  	</div> 
  </body>
</html>
